from selenium import webdriver
import time
from selenium.webdriver.support.select import Select

browser =webdriver.Firefox();
browser.get('http://192.168.1.141:9999/login')
time.sleep(2)
browser.find_element_by_id('username').send_keys('miaojiahang')
browser.find_element_by_id('password').send_keys('123abc')
browser.find_element_by_xpath('html/body/div[1]/form/button').click()
time.sleep(3)
browser.find_element_by_link_text('新增车辆').click()
sreach_window=browser.current_window_handle

time.sleep(3)
browser.find_element_by_css_selector('#brand').send_keys('宝马')
browser.find_element_by_css_selector('#model').send_keys('X5')
browser.find_element_by_css_selector('#displacement').send_keys('1.2T')
sel = browser.find_element_by_css_selector('#gearbox')
Select(sel).select_by_value('AT')  #变速箱

browser.find_element_by_css_selector('#vin').send_keys('ceshi')
browser.find_element_by_css_selector('#engine_number').send_keys('test')
browser.find_element_by_css_selector('#registration_no').send_keys('test')
browser.find_element_by_css_selector('#plate_number').send_keys('123456')
browser.find_element_by_css_selector('#price').send_keys('60000')
browser.find_element_by_css_selector('#init_distance').send_keys('100')
browser.find_element_by_css_selector('#type').send_keys('火车')
browser.find_element_by_css_selector('#gps_number').send_keys('123456')
browser.find_element_by_css_selector('#purpose').send_keys('自用')
sel = browser.find_element_by_css_selector('#accident')
Select(sel).select_by_value('False')  #变速箱

js = 'document.getElementById("registration_year").removeAttribute("readonly");'
browser.execute_script(js)
browser.find_element_by_css_selector('#registration_year').send_keys('2017')
browser.find_element_by_css_selector('.btn.btn-default.pull-right.apply.disabled').click()